﻿
namespace AdventureWorksDomainService
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Web.Ria;
    using System.Web.Ria.Data;
    using System.Web.DomainServices;
    using System.Data;
    using System.Web.DomainServices.LinqToEntities;


    // Implements application logic using the AdventureWorksEntities context.
    // TODO: Add your application logic to these methods or in additional methods.
    [EnableClientAccess()]
    public class Catalog : LinqToEntitiesDomainService<AdventureWorksEntities>
    {

        // TODO: Consider
        // 1. Adding parameters to this method and constraining returned results, and/or
        // 2. Adding query methods taking different parameters.
        public IQueryable<Product> GetProduct()
        {
            return this.Context.Product;
        }

        public void InsertProduct(Product product)
        {
            this.Context.AddToProduct(product);
        }

        public void UpdateProduct(Product currentProduct, Product originalProduct)
        {
            this.Context.AttachAsModified(currentProduct, originalProduct);
        }

        public void DeleteProduct(Product product)
        {
            if ((product.EntityState == EntityState.Detached))
            {
                this.Context.Attach(product);
            }
            this.Context.DeleteObject(product);
        }

        // TODO: Consider
        // 1. Adding parameters to this method and constraining returned results, and/or
        // 2. Adding query methods taking different parameters.
        public IQueryable<ProductCategory> GetProductCategory()
        {
            return this.Context.ProductCategory;
        }

        public void InsertProductCategory(ProductCategory productCategory)
        {
            this.Context.AddToProductCategory(productCategory);
        }

        public void UpdateProductCategory(ProductCategory currentProductCategory, ProductCategory originalProductCategory)
        {
            this.Context.AttachAsModified(currentProductCategory, originalProductCategory);
        }

        public void DeleteProductCategory(ProductCategory productCategory)
        {
            if ((productCategory.EntityState == EntityState.Detached))
            {
                this.Context.Attach(productCategory);
            }
            this.Context.DeleteObject(productCategory);
        }
    }
}


